import Vue from 'vue'
import Vuex from 'vuex'
import  * as types from '../store/types'

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    user : {},
    token : null,
    nodeList: [],                         //存放关系图的节点集合
    interfaceNode: {},                    //存放当前拖拽的接口对象
    parentInterfaceList: [],              //存放当前节点的父节点
    systemName: "运维监控",               //系统名称
  },
  getters:{
    nodeList: (state) => {
      return state.nodeList
    },
    interfaceNode: (state) => {
      return state.interfaceNode
    },
    parentInterfaceList: (state) => {
      return state.parentInterfaceList
    },
    getSystemName: (state) => {
      return state.systemName
    }
  },
  mutations:{
    setSystemName: (state, data) => {
      state.systemName = data;
    },
    /*配置公共*/
    [types.LOGIN] : (state,data) => {
      localStorage.token = data;
      state.token = data;
    },
    [types.LOGOUT] : (state,data) => {
      localStorage.removeItem('token');
      localStorage.removeItem('user');
      state.token = null;
    },
    [types.TITLE] : (state,data) => {
      state.title = data;
    },
    [types.USERS] : (state,data) => {
      localStorage.user = JSON.stringify(data);
      state.user = data;
    },
    [types.NODELIST] : (state,data) => {
      state.nodeList = data;
    },
    [types.INTERFACENODE] : (state,data) => {
      state.interfaceNode = data;
    },
    [types.PARENTINTERFACELIST] : (state,data) => {
      state.parentInterfaceList = data;
    },
  },
  actions:{

  },
  modules:{

  }
});

export default store
